package cn.hwy.societies.web;

import cn.hwy.societies.web.club.result.ClubCreateResult;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Integer code;

    private String error;

    private T data;

    public static <T> Result<T> success(T result) {
        Result<T> obj = new Result<>();
        obj.setCode(200);
        obj.setData(result);
        return obj;
    }

    public static <T> Result<T> success(Integer code, T result) {
        Result<T> obj = new Result<>();
        obj.setCode(code);
        obj.setData(result);
        return obj;
    }

    public static <T> Result<T> fail(String error) {
        Result<T> obj = new Result<>();
        obj.setCode(-1);
        obj.setError(error);
        obj.setData(null);
        return obj;
    }

    public static <T> Result<T> fail(Integer code, String error) {
        Result<T> obj = new Result<>();
        obj.setCode(code);
        obj.setError(error);
        obj.setData(null);
        return obj;
    }
}
